package com.woniuxy.store.core.service.impl;

import com.woniuxy.store.core.mapper.MdSsMapper;
import com.woniuxy.store.core.mapper.MdStMapper;
import com.woniuxy.store.core.model.MdSf;
import com.woniuxy.store.core.mapper.MdSfMapper;
import com.woniuxy.store.core.service.MdSfService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.store.core.vo.ServeVo;
import com.woniuxy.store.core.vo.CountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Service
public class MdSfServiceImpl extends ServiceImpl<MdSfMapper, MdSf> implements MdSfService {

    @Autowired(required = false)
    MdSfMapper mdSfMapper;

    @Autowired
    MdSsMapper mdSsMapper;

    @Autowired
    MdStMapper mdStMapper;

    @Override
    public void insertOne(MdSf mdSf) {
        mdSfMapper.insert(mdSf);
    }

    @Override
    public void delectOne(int sfId) {
        mdSfMapper.delectOne(sfId);

    }

    @Override
    public void serveManagement(ServeVo serveVo) {
        Integer serve = serveVo.getServe();
        Integer storeId = serveVo.getStoreId();

        if(serve == 1){
            List<Integer> firstIds = serveVo.getFirstId();
            for (Integer firstId:firstIds) {
                mdSfMapper.updateFlag(storeId,firstId);
            }
        }
        else if (serve == 2){
            List<Integer> secondIds = serveVo.getSecondId();
            for (Integer secondId:secondIds) {
                mdSsMapper.updateFlag(storeId,secondId);
            }
        }
        else if(serve == 3){
            List<Integer> thirdIds = serveVo.getThirdId();
            for (Integer thirdId:thirdIds) {
                mdStMapper.updateFlag(storeId,thirdId);
            }
        }
    }

    @Override
    public void fabu(Integer storeId, Integer firstId, Integer secondId, Integer thirdId) {

        mdSfMapper.fabuf(storeId,firstId);
        mdSfMapper.fabus(storeId,secondId);
        mdSfMapper.fabut(storeId,thirdId);
    }

    @Override
    public List<MdSf> selectServe(Integer storeId) {

        List<MdSf> firstServe = mdSfMapper.selectFirstServe(storeId);

        return firstServe;
    }

    @Override
    public void serviceOnAndOff(Integer id) {
        mdSfMapper.updateFlagById(id);
    }

    @Override
    public CountVo countServe(Integer storeId) {
        CountVo countVo = new CountVo();

        Integer quantityOnShelves = mdSfMapper.quantityOnShelves(storeId);
        Integer quantityOffTheShelf = mdSfMapper.quantityOffTheShelf(storeId);
        countVo.setQuantityOnShelves(quantityOnShelves);
        countVo.setQuantityOffTheShelf(quantityOffTheShelf);

        return countVo;
    }

    @Override
    public Integer countFirstServe(Integer firstId) {
        return mdSfMapper.count(firstId);
    }


}
